package com.qingke.service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.ibatis.session.SqlSession;

import com.qingke.dao.WSessionFactory;
import com.qingke.dao.WordDAO;

public class MyLoadService {

	private static WordDAO dao = new WordDAO();
	public static void main(String[] args) {
		
		try {
			InputStream is = WSessionFactory.class.getClassLoader().getResourceAsStream("dict.txt");
			BufferedReader br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
			String line;
			line = br.readLine();
			SqlSession session = WSessionFactory.getInstance().getSession();
			while(line!=null) {
				int index = line.indexOf(" ");
				String en = line.substring(0,index).trim();
				String cn = line.substring(index,line.length()-1).trim();
				dao.insertWord(session,en, cn);
				System.out.println(en+":"+cn);
				line = br.readLine();
			}
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
